package chapter06.ExamPle03;

import java.util.ArrayList;
import java.util.Iterator;

public class ExamPle03 {
    public static void main (String [] args){
        // 迭代器 Iterator 遍历集合
        ArrayList list = new ArrayList();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("赵六");
        Iterator it = list.iterator();// 返回一个list对象的迭代器
        while (it.hasNext()){
            Object obj = it.next();
            System.out.println(obj);
        }
        System.out.println("for循环迭代集合");

        for (Object obj:list){
            System.out.println(obj);
        }
    }
}
